<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCustomersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('customers', function (Blueprint $table) {
            $table->id();
            $table->string('name',20)->default('')->comment('用户姓名');
            $table->string('mobile',20)->default('')->comment('用户手机号');
            $table->char('salt',10)->default('')->comment('盐');
            $table->string('password',100)->default('')->comment('密码');
            $table->string('headImage',100)->default('')->comment("用户头像");
            $table->integer('lastLoginAt')->default(0)->comment('最后登录时间');
            $table->bigInteger('lastLoginIpAt')->default(0)->comment('最后登录ip');
            $table->integer('loginTimes')->default(0)->comment('登录次数');
            $table->tinyInteger('isDeleted')->default(0)->comment("是否删除 0：未删除，1：已删除");
            $table->integer("createdAt")->default(0)->comment("创建时间");
            $table->integer("updatedAt")->default(0)->comment("修改时间");

            $table->index("createdAt", "idx_created_at");
            $table->index('mobile','idx_mobile');

            $table->collation = 'utf8mb4_general_ci';
        });

        $prefix = config('other.DB_PREFIX', '');
        \Illuminate\Support\Facades\DB::statement("ALTER TABLE `{$prefix}customers` COMMENT = '顾客基本信息'"); //表注释
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('customers');
    }
}
